<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/7/1
 * Time: 下午4:02
 */

namespace App\Logic;
use App\Http\Model\Bundle AS BundleModel;
use Exception;

class BundleLogic extends BaseLogic
{
    protected $_bundle = null;

    public function __construct($bundle)
    {
        $this->_bundle = $bundle;
    }

    public static function initByBundle($bundle)
    {
        if (is_numeric($bundle))
        {
            $bundle = BundleModel::find($bundle);
            if (!$bundle)
            {
                throw new Exception("捆绑商品信息不存在", -2);
            }
        }else if (!$bundle instanceof BundleModel)
        {
            throw new Exception("捆绑商品参数错误", -2);
        }
        return new static($bundle);
    }

    public static function create()
    {
        $bundle = new BundleModel();
        return new static($bundle);
    }

    public function getBundle()
    {
        return $this->_bundle;
    }
    
}